package com.hellogood.yaohuo.server.serviceImpl;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.hellogood.yaohuo.server.mgr.factory.MgrFactory;
import com.hellogood.yaohuo.shared.entity.Form;
import com.hellogood.yaohuo.shared.entity.PsForm;
import com.hellogood.yaohuo.shared.services.PeisongService;

@SuppressWarnings("serial")
public class PeisongServiceImpl extends RemoteServiceServlet implements PeisongService {

	@Override
	public List<Form> searchPeisongFormByOrgCodeAndDate(String code, int level, String startDate, String endDate, String rz) {
		return MgrFactory.getInstance().createPeisongMgr().searchPsForm(code, level, startDate, endDate, rz);
	}

	@Override
	public Form getFormDetail(String billNo) {
		return MgrFactory.getInstance().createPeisongMgr().getFormDetail(billNo);
	}

	@Override
	public String deleteForm(String billNo) {
		return MgrFactory.getInstance().createPeisongMgr().deletePeisong(billNo);
	}

	@Override
	public String saveForm(PsForm form, boolean isModify) {
		if (isModify) {
			return MgrFactory.getInstance().createPeisongMgr().modifyPeisongForm(form);
		} else {
			return MgrFactory.getInstance().createPeisongMgr().createPeisongForm(form);
		}
	}

	@Override
	public String bankForm(List<String> bills) {
		return MgrFactory.getInstance().createPeisongMgr().rz(bills);
	}

	@Override
	public String getLastPsBillNo(String orgCode) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		DecimalFormat df = new DecimalFormat("0000");
		String billNo = "PS" + sdf.format(new Date());
		int lastNo = MgrFactory.getInstance().createPeisongMgr().getLastPsBillNo(billNo);
		lastNo++;
		billNo += df.format(lastNo);
		return billNo;
	}

}
